var netDrop = 0;
layui.use([ 'element', 'layer', 'jquery' ], function() {
    //实现页面右侧显示
    $(document).ready(function(){
        $("dd>a").click(function (e) {
            //取消事件的默认动作,这里取消跳转
            e.preventDefault();
            //attr() 设置或返回被选元素的属性值,第二个参数不填则获取属性，填了则设置参数
            //$(this)这里是a标签
            $("#theBody").attr("src",$(this).attr("href"));
        });
    });
    //设置剩余停车位
    getCarPlaceNum();
    setInterval("getCarPlaceNum()", 5000);
});

function getCarPlaceNum () {
    $.ajax({
        url: "/carNum",
        success:function(res){
            var maxPlace = "总车位："+res[0];
            var usedPlace = "占用车位："+res[1];
            var nowPlace = "剩余车位："+(res[0]-res[1]);
            document.getElementById("remainingSpace").innerText=maxPlace+"  "+usedPlace+"  "+nowPlace;
        },
        error: function () {
            netDrop ++;
        }
    });
    if (netDrop === 10){
        layer.alert("网络连接异常");
        window.location.href="../login.html"
    }
}